<template>
    <div id="addpath">
        <div class="top">
                <span @click="goback" class="iconfont"> &#xe6bc; </span>
                <span>地址管理</span>
        </div>
        <main>
            <div v-for="item in addresslist" :key="item.id" @click="selectpath(item.id)">
                <p @click.stop="pathdelete(item.id)">x</p>
                <p><span>{{item.username}}</span><span>{{item.userphone}}</span><span v-if="item.status==1">默认</span></p>
                <p><span>{{item.location+item.useraddress}}</span><span @click.stop="pathedit(item.id)">修改</span></p>
            </div>
        </main>
        <div class="bottom" @click="goaddpaths">
            +新建收货地址
        </div>
    </div>
</template>

<script>
import {mapActions,mapGetters} from 'vuex'
import {addressremove} from '../utils/api'
export default {
    data(){
        return{
            userinfo:""
        }
    },
    methods:{
        ...mapActions({
            reqChangeAddresslist:"addresspath/reqChangeAddresslist"
        }),
        goaddpaths(){
            this.$router.push("/addpaths")
        },
        goback(){
            this.$router.push("/paynow")
        },
        pathdelete(id){
            addressremove({id:id}).then(res=>{
                if(res.data.code==200){
                    this.reqChangeAddresslist({uid:this.userinfo.uid})
                }
                else{
                    alert(res.data.msg)
                }
            })
        },
        pathedit(id){
            this.$router.push("/addpaths?id="+id)
        },
        selectpath(id){
            this.$router.push("/paynow?id="+id)
        }
    },
    computed:{
        ...mapGetters({
            addresslist:"addresspath/list"
        })
    },
    mounted(){  
        this.userinfo=sessionStorage.getItem("user")?JSON.parse(sessionStorage.getItem("user")):{}
        this.reqChangeAddresslist({uid:this.userinfo.uid})
    }
}
</script>


<style  scoped>
#addpath{
        height: 100%;
        background-color: #fff;
        position: relative;
}
#addpath main{
    flex: 1;
    margin: 0;
    padding:1.2rem 0 1rem;
}
#addpath main div{
    padding-left:0.3rem ;
}
#addpath main div p:nth-child(1){
    margin-top: 0.3rem;
    width: 0.3rem;
    height: 0.3rem;
    background-color: red;
    border-radius: 50%;
    text-align: center;
    color: #fff;
}
#addpath main div p:nth-child(2){
    margin-top: 0.15rem;
}
#addpath main div p:nth-child(2) span:nth-child(1),#addpath main div p:nth-child(2) span:nth-child(2){
    font-weight:bold ;
    font-size: 0.32rem;
    display: inline-block;
    width: 2.5rem;
}
#addpath main div p:nth-child(2) span:nth-child(2){
    margin-left: 0.1rem;
}
#addpath main div p:nth-child(2) span:nth-child(3){
    display: inline-block;
    background-color: red;
    color: #fff;
    line-height: 0.4rem;
    font-size: 0.32rem;
    margin-left: 0.3rem;
}
#addpath main div p:nth-child(3){
    display: flex;
    justify-content: space-between;
     font-size: 0.32rem;
     color: #a1a0a0;
     margin-top: 0.2rem;
}
#addpath main div p:nth-child(3) span:nth-child(2){
    margin-right: 0.3rem;
}
#addpath .top{
    height: 1.2rem;
    width: 100%;
    background-color: #ff7560;
    display: flex;
    justify-content: space-between;
    position: fixed;
    left: 0;
    top: 0;
}
#addpath .top span{
    color: #fff;
    font-size: 0.36rem;
    display: block;
    line-height: 1.2rem;
}
#addpath .top span:nth-child(1){
    margin-left: 0.4rem;
    font-size: 0.8rem;
    line-height: 1.0rem;
}
#addpath .top span:nth-child(2){
    margin-right: 2.4rem;
}
#addpath .bottom{
    position: fixed;
    bottom: 0;
    left: 50%;
    height: 1rem;
    width: 5.6rem;
    background-color: #ff0000;
    border-radius: 0.5rem;
    margin-left:-2.8rem ;
    color: #fff;
    text-align: center;
    line-height: 1rem;
    font-size: 0.3rem;
}
</style>
